#pragma once 
#include <iostream>
using namespace std;
#include <unistd.h>
class Handler{
    public:    
    Handler() = default;    
    void operator()(int sock)    
    {    
        cout << "get a new linl :  " << sock  << endl;    
        char buff[1024];                                                                                                                                  while(true)        
        {    
          ssize_t size = read(sock , buff , sizeof(buff) - 1);                                                                                      
          if (size > 0)    
          {    
            buff[size] = 0; // '\0'    
            cout << buff << endl;    
            write(sock , buff , size);    
         }    
          else if (size == 0)    
          {    
            cout << "read close" << endl; 
            break;
          }
          else 
          {
            cout << "unknown error" << endl;
          }
       }
        close(sock);
        cout << "Service end sock closed" << endl;
    }
  };

class Task
{
  private:
    int _sock;
    Handler _handler;
  public:
    Task(int sock)
      :_sock(sock)
    {}

    Task() = default;
    void run()
    {
      _handler(_sock);
    }
};
